package edu.chl.grupp11.aegas.view;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Observable;
import java.util.ResourceBundle;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JRadioButton;

import org.swixml.SwingEngine;

import edu.chl.grupp11.aegas.model.AbstractConfig;
import edu.chl.grupp11.aegas.model.ConfigFactory;

public class SettingsBox extends Observable implements ActionListener {
	private JRadioButton deepSearch, shallowSearch;
	private JButton settingsOkButton;
	private JFrame settingsFrame;
	private JLabel includeLabel;
	private JLabel noLabel;
	private JLabel yesLabel;

	public SettingsBox() throws Exception {
		SwingEngine se = new SwingEngine(this);

		se.render("edu/chl/grupp11/aegas/view/xml/SettingsView.xml")
				.setVisible(true);
		AbstractConfig config = ConfigFactory.getSharedConfig();

		if (config.isSearchSubFolders()) {
			deepSearch.setSelected(true);
		} else {
			shallowSearch.setSelected(true);
		}

		settingsOkButton.addActionListener(this);

	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == settingsOkButton) {
			settingsFrame.setVisible(false);
			setChanged();
			notifyObservers();
		}

	}

	public boolean getSearchSubFolders() {
		return deepSearch.isSelected();
	}

	public void setText(ResourceBundle bundle) {
		includeLabel.setText(bundle.getString("include"));
		yesLabel.setText(bundle.getString("yes"));
		noLabel.setText(bundle.getString("no"));
	}
}
